/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Logica;

import java.io.IOException;
import java.io.Reader;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;

/**
 *
 * @author Diego
 */
public class WSDecoder implements Decoder.TextStream<Coordenadas>{

    @Override
    public Coordenadas decode(Reader reader) throws DecodeException, IOException {
        Coordenadas coordenadas = new Coordenadas();
        try(JsonReader jsonReader = Json.createReader(reader)){
            JsonObject jsonCoordenadas = jsonReader.readObject();
            coordenadas.setx(jsonCoordenadas.getInt("x"));
            coordenadas.sety(jsonCoordenadas.getInt("y"));
        }
        
        return coordenadas;
    }

    @Override
    public void init(EndpointConfig config) {
    }

    @Override
    public void destroy() {
    }
    
}